<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0 ,minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
		<title>结算页面</title>
		<link href="AmazeUI-2.4.2/assets/css/amazeui.css" rel="stylesheet" type="text/css" />
		<link href="basic/css/demo.css" rel="stylesheet" type="text/css" />
		<link href="css/cartstyle.css" rel="stylesheet" type="text/css" />
		<link href="css/jsstyle.css" rel="stylesheet" type="text/css" />
		<script type="text/javascript" src="js/address.js"></script>
		<script type="text/javascript">
			$(function(){
			
				
				$.ajax({
		               url:"receipt.do?type=querylist",
		               type:"POST",
		               data:{},  //传递的参数
		               dataType:"JSON",
		               
		               success:function(data){//返回成功的操作
		                 $(".theme-popover").hide();
		              	 var s="";
		              	 var receshow=$("#receiptshow");
		              	 	receshow.show();//显示收货地li
						receshow.empty();//清空li下所有的子元素(不包含本身)
						$.each(data.receiptlist,function(index,obj){//第一个表示集合的下标，第二个参数表示这个集合的对象
							  html = "<li class='user-addresslist'<div class='address-left'><div class='user DefaultAddr'><span class='buy-address-detail'><span class='buy-user'>"+obj.receipt_name +"</span>"+
											"<span class='buy-phone'>"+obj.receipt_phone+"</span>"+"</span>"+"</div>"+"<div class='default-address DefaultAddr'><span class='buy-line-title buy-line-title-type'>收货地址：</span><span class='buy--address-detail'><span class='province'>"+obj.receipt_addr+"</span>"+
										"</div>"+"</div>"+"<div class='address-right'><span class='am-icon-angle-right am-icon-lg'></span></div><div class='clear'></div><div class='new-addr-btn'><a href='javascript:void(0);' onclick='del(this,"+obj.receipt_id+")'>删除</a></div></li>"
								s+=html;
							});
							var result=s;
							$(result).appendTo(receshow);
		
					},
					error:function(){//请求失败要执行的操作
					}
				});
			
				$("#recesave").on("click",function(){
					var receipt_name=$("#receipt_name");
					var receipt_phone=$("#receipt_phone");
					var receipt_addr=$("#receipt_addr");
					if(receipt_name.val()==null||receipt_name.val()==""){
						alert("姓名不能为空！请重输");
						receipt_name.focus();
						return false;
					}
					if(receipt_phone.val()==null||receipt_phone.val()==""){
						alert("电话号码不能为空！请重输");
						receipt_phone.focus();
						return false;
					}
					if(receipt_addr.val()==null||receipt_addr.val()==""){
						alert("地址不能为空！请重输");
						receipt_addr.focus();
						return false;
					}
			
					$.ajax({
		               url:"receipt.do?type=save",
		               type:"POST",
		               data:{receipt_name:receipt_name.val(),receipt_phone:receipt_phone.val(),receipt_addr:receipt_addr.val()},  //传递的参数
		               dataType:"JSON",
		               
		               success:function(data){//返回成功的操作
		                 if(data.code==0){
		                  window.location.href="**?id="+data.id;
		                 }
		                 $(".theme-popover").hide();
		              	 var s="";
		              	 var receshow=$("#receiptshow");
		              	 	receshow.show();//显示收货地li
						receshow.empty();//清空li下所有的子元素(不包含本身)
						$.each(data.receiptlist,function(index,obj){//第一个表示集合的下标，第二个参数表示这个集合的对象
							  html = "<li class='user-addresslist'<div class='address-left'><div class='user DefaultAddr'><span class='buy-address-detail'><span class='buy-user'>"+obj.receipt_name +"</span>"+
											"<span class='buy-phone'>"+obj.receipt_phone+"</span>"+"</span>"+"</div>"+"<div class='default-address DefaultAddr'><span class='buy-line-title buy-line-title-type'>收货地址：</span><span class='buy--address-detail'><span class='province'>"+obj.receipt_addr+"</span>"+
										"</div>"+"</div>"+"<div class='address-right'><span class='am-icon-angle-right am-icon-lg'></span></div><div class='clear'></div><div class='new-addr-btn'><a href='javascript:void(0);' onclick='del(this,"+obj.receipt_id+");'>删除</a></div></li>"
								s+=html;
							});
							var result=s;
							$(result).appendTo(receshow);
		
					},
					error:function(){//请求失败要执行的操作
					}
				});
		     });
		});
		
		 function del(obj,id){
   		var parent=$(obj).parent().parent();
   		$.ajax({
   		 	url:"receipt.do?type=delete",//返回的Url地址
   			type:"POST",
   			dataType:"JSON",//服务器返回的数据类型
   			data:{receipt_id:id},
   			success:function(data){
   				parent.remove();
   			},
   			error:function(){//请求失败要执行的操作
			alert("error");
			}
   			
   		});
   }
		</script>
		
		
		
		
</head>
<body>
	<form action="address.do?type=add" method="post">
		<!--信息 -->
		<div class="order-go clearfix">
			<div class="pay-confirm clearfix">
				<div class="box">
					<div tabindex="0" id="holyshit267" class="realPay"><em class="t">实付款：</em>
						<span class="price g_price ">
	                             <!--  //<span>¥</span> <em class="style-large-bold-red " id="J_ActualFee" name="oder_price">	</em> -->
	                              <input type="text" name="oder_price"/>
						</span>
					</div>
	
					<div id="holyshit268" class="pay-address">
	
						<p class="buy-footer-address" name="receipt_name">
							<span class="buy-line-title buy-line-title-type">寄送至：</span>
							<!-- <span class="buy--address-detail">
			   				<span class="province">湖北</span>省
							<span class="city">武汉</span>市
							<span class="dist">洪山</span>区
							<span class="street">雄楚大道666号(中南财经政法大学)</span> -->
							 <input type="text" name="receipt_addr"/>
							</span>
							</span>
						</p>
						<p class="buy-footer-address">
							<span class="buy-line-title">收货人：</span>
							<span class="buy-address-detail">   
							 <input type="text" name="receipt_name"/>
	                                <!--    <span class="buy-user" name="receipt_name">艾迪 </span> -->
							<!-- <span class="buy-phone" name="receipt_name">15871145629</span> -->
							 <input type="text" name="receipt_phone"/>
							</span>
						</p>
					</div>
				</div>
	
				<div id="holyshit269" class="submitOrder">
					<div class="go-btn-wrap">
						<a id="J_Go" href="success.jsp" class="btn-go" tabindex="0" title="点击此按钮，提交订单">提交订单</a>
						<input type="submit"  name="提交"/>
					</div>
				</div>
				<div class="clear"></div>
			</div>
		</div>
		</form>
	
	
	<div class="clear"></div>
	
	

		
	</body>

</html>